<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <title>
            <?php echo $title ?> <?php echo C('SITE_NAME') ?>
        </title>
        <link rel="stylesheet" href="//at.alicdn.com/t/font_001z27klwvobt9.css">
        <link rel="stylesheet" href="/fly/Public/css/layui.css">
        <link rel="stylesheet" href="/fly/Public/css/global.css">
        <script src="/fly/Public/layui.js"></script>
        <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    </head>
    
    <body>
        <div class="header">
            <div class="main">
                <a class="logo" href="<?php echo U('home/index/index');?>" title="Fly">
                    Fly社区
                </a>
                <div class="nav">
                    <a href="<?php echo U('home/index/wenda');?>">
                        <i class="iconfont icon-wenda">
                        </i>
                        问答
                    </a>
                    <?php if (isset($_SESSION['username'])) { ?>
                    <a href="<?php echo U('home/shiping/index');?>">
                        <i class="iconfont icon-iconmingxinganli" style="top: 2px;">
                        </i>
                        视频
                    </a>
                    <?php } ?>
                    <a href="http://www.layui.com/">
                        <i class="iconfont icon-ui">
                        </i>
                        框架
                    </a>
                </div>
                <?php if(userCheck()): ?><div class="nav-user">
                    <a class="avatar" href="<?php echo U('home/user/myuser');?>">
                        <img class="face" src="/fly<?php echo ($_SESSION['face']); ?>">
                        <cite>
                            <?php echo ($_SESSION['username']); ?>
                        </cite>
                    </a>
                    <div class="nav">
                        <a href="<?php echo U('home/user/myset');?>">
                            <i class="iconfont icon-shezhi">
                            </i>
                            设置
                        </a>
                        <a href="<?php echo U('home/login/logout');?>">
                            <i class="iconfont icon-tuichu" style="top: 0; font-size: 22px;">
                            </i>
                            退了
                        </a>
                    </div>
                </div>
                <?php else: ?>
                <div class="nav-user">
                    <a class="unlogin" href="<?php echo U('home/user/index');?>">
                        <i class="iconfont icon-touxiang">
                        </i>
                    </a>
                    <span>
                        <a href="<?php echo U('home/login/index');?>">
                            登入
                        </a>
                        <a href="<?php echo U('home/reg/index');?>">
                            注册
                        </a>
                    </span>
                    <p class="out-login">
                    <?php if (sys_is_qq()==1) { ?>
                        <a href="<?php echo U('home/login/qqlogin');?>" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})"class="iconfont icon-qq" title="QQ登入"></a>
                    <?php } ?>
                        <a href="http://fly.layui.com:8098/app/weibo/" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})"
                        class="iconfont icon-weibo" title="微博登入">
                        </a>
                    </p>
                </div><?php endif; ?>
            </div>
        </div>
        <div class="main layui-clear">
    <div class="wrap">
        <div class="content detail">
            <h1>
                <?php echo ($question_msg['title']); ?>
            </h1>
            <div class="fly-tip fly-detail-hint" data-id="6530">
                <span>
                    <?php echo ($question_msg['status']); ?>
                </span>
                <div class="fly-list-hint">
                    <i class="iconfont" title="回答">
                        &#xe60c;
                    </i>
                    <?php echo ($question_msg['answer_num']); ?>
                    <i class="iconfont" title="人气">
                        &#xe60b;
                    </i>
                    <?php echo ($question_msg['view_num']); ?>
                </div>
            </div>
            <div class="detail-about">
                <a class="jie-user" href="<?php echo U('home/user/my',array('id'=>$question_msg['uid']));?>">
                    <img src="/fly<?php echo ($question_msg['face']); ?>"
                    alt="<?php echo ($question_msg['username']); ?>">
                    <cite>
                        <?php echo ($question_msg['username']); ?>
                        <em>
                            发布于<?php echo ($question_time); ?>
                        </em>
                    </cite>
                </a>
                <div class="detail-hits" data-id="6530">
                    <span style="color:#FF7200">
                        悬赏：<?php echo ($question_msg['kiss']); ?>飞吻
                    </span>
                    <?php if ($question_msg['uid']==$_SESSION['id']) { ?>
                       <span class="jie-admin" type="edit">
                        <a href="<?php echo U('home/question/question_edit',array('id'=>$question_msg['id']));?>">
                            编辑此贴
                        </a>
                    </span>
                    <?PHP } ?> 
                </div>
            </div>
            <div class="detail-body photos" style="margin-bottom: 20px;">
                <?php echo htmlspecialchars_decode($question_msg['content']) ?>
            </div>
            <a name="comment">
            </a>
            <h2 class="page-title">
                热忱回答
                <span>
                </span>
            </h2>
              
           <?php foreach ($answer as $a) { ?>
            <ul class="jieda photos" id="jieda">
                <li data-id="23029">
                    <a name="item-1483533236945">
                    </a>
                    <div class="detail-about detail-about-reply">
                        <a class="jie-user" href="<?php echo U('home/user/my',array('id'=>$a['uid']));?>">
                            <img src="/fly<?php echo ($a['face']); ?>" alt="<?php echo ($a['username']); ?>" layer-index="1">
                            <cite class='aaaaaaaaaa'>
                                <i>
                                    <?php echo ($a['username']); ?>
                                </i>
                                <em style="color:#5FB878">
                                    <!-- (管理员) -->
                                </em>
                            </cite>
                        </a>
                        <div class="detail-hits">
                            <span>
                                <?php echo run($a['create_time'])?>
                            </span>
                        </div>
                    </div>
                    <div class="detail-body jieda-body">
                        <?php echo htmlspecialchars_decode($a['content'])?>
                    </div>
                    <div class="jieda-reply">
                        <span class="jieda-zan" type="zan" zan="<?php echo ($a['id']); ?>">
                            <i class="iconfont icon-zan">
                            </i>
                            <em class='resdianzan'>
                               <?php echo ($a['zan']); ?>
                            </em>
                        </span>
                        <span class='huifu' type="reply" username="<?php echo ($a['username']); ?>" userid="<?php echo ($a['uid']); ?>">
                            <i class="iconfont icon-svgmoban53">
                            </i>
                            回复
                        </span>
                        <div class="jieda-admin">
                        <?php if ($a['status']==0 && $question_msg['username']==$_SESSION['username']) { ?>
                            <span class="jieda-accept" statusid="<?php echo ($a['id']); ?>" type="accept">
                                采纳
                            </span>
                        <?php }elseif ($a['status']==1) { ?>
                            <i class="iconfont icon-caina" style="font-size:80px;right:80px;top:-60px;" title="最佳答案"></i>
                        <?php } ?>
                        </div>
                    </div>
                </li>
             <?php } ?>    
            </ul>
            <div class="layui-form layui-form-pane">
                <form action="" method="post">
                    <div class="layui-form-item layui-form-text">
                        <div class="layui-input-block">
                            <textarea id="L_content" name="content" 
                            placeholder="我要自问自答" class="layui-textarea fly-editor" style="height: 150px;">
                            </textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <input type="hidden" name="qid" value="<?php echo ($question_msg['id']); ?>">
                        <input type="hidden" name="uid" value="<?php echo ($_SESSION['id']); ?>">
                        <button class="layui-btn" lay-filter="*" lay-submit>
                            提交回答
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="edge">
        <h3 class="page-title">
            最近热帖
        </h3>
        <ol class="fly-list-one">
        <?php foreach ($zuijinhot as $h) { ?>
            <li>
                <a href="<?php echo U('home/question/question',array('id'=>$h['id']));?>">
                    <?php echo ($h['title']); ?>
                </a>
                <span>
                    <i class="iconfont">
                        &#xe60b;
                    </i>
                    <?php echo ($h['view_num']); ?>
                </span>
            </li>
        <?php } ?>
        </ol>
        <h3 class="page-title">
            近期热议
        </h3>
        <ol class="fly-list-one">
        <?php foreach ($zuijinhotyi as $y) { ?>
            <li>
                <a href="<?php echo U('home/question/question',array('id'=>$y['id']));?>">
                    <?php echo ($y['title']); ?>
                </a>
                <span>
                    <i class="iconfont">
                        &#xe60c;
                    </i>
                    <?php echo ($y['answer_num']); ?>
                </span>
            </li>
        <?php } ?>
        </ol>
    </div>
</div>
<script>
    layui.use(['form','layer','layedit' ,'laypage', 'element'], function(){
      var layer = layui.layer
      ,laypage = layui.laypage
      ,layedit = layui.layedit
      ,element = layui.element()
      ,form = layui.form();

  //点击异步 answer表赞字段一
  $('.jieda-zan').click(function(){   
    obj = $(this);
    zan = $(this).attr('zan');
    //alert(zan);
    $.ajax({
        url: "<?php echo U('home/question/dianzan');?>",//请求地址
        type: "post",//请求方式
        dataType: "json",//返回数据类型
        data: {zan:zan},//发送的参数
        })
        .done(function(response) {
              if(response.error==0){
                 layer.msg(response.info ,{icon:5});
              }else{
                layer.msg(response.info ,{icon:6});
                obj.children('.resdianzan').html(response.zan);
              }
          })
        .fail(function() {
            alert("ajxs交互失败");
        })  
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });  
  //点击异步 question,answer表status字段变为    采纳 ,1
  $('.jieda-accept').click(function(){   
    statusid = $(this).attr('statusid');
    $.ajax({
        url: "<?php echo U('home/question/caina_status');?>",//请求地址
        type: "post",//请求方式
        dataType: "json",//返回数据类型
        data: {statusid:statusid},//发送的参数
        })
        .done(function(response) {
              if(response.error==0){
                 layer.msg(response.info ,{icon:5});
              }else{
                 layer.alert(response.info ,{icon:6},function(){
                    location.href = response.url;
                 });
              }
          })
        .fail(function() {
            alert("ajxs交互失败");
        })  
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    }); 

      layedit.set({
      uploadImage: {
        url: "<?php echo U('home/question/img');?>" //接口url
        ,type: 'post' //默认post
      }
    })    

  //创建一个编辑器
  var editIndex = layedit.build('L_content');

  //点击回复 同步回复人的username到编辑器
  $('.huifu').click(function(){
    //alert('qqqqqqqq');
    //异步回复uid
        answeruserid = $(this).attr('userid'); 
        $.ajax({
        url: "<?php echo U('home/question/answeruserid');?>",//请求地址
        type: "post",//请求方式
        dataType: "json",//返回数据类型
        data: {answeruserid:answeruserid},//发送的参数
        })
        .done(function(response) {
              if(response.error==0){
                 layer.msg(response.info ,{icon:5});
              }else{
                layer.msg(response.info ,{icon:6});
              }
          })
        .fail(function() {
            alert("ajxs交互失败");
        })  
    var answerurl = "<?php echo U('home/user/my',array('id'=>'answeruserid'));?>"; //sting
    answerurll =  answerurl.replace("answeruserid",answeruserid); //将代替变量的字符串用真实变量替换
    content = layedit.getText(editIndex);   
    //username ='@'+'<a href="<?php echo U('home/user/my',array('id'=>$_SESSION['answeruserid']));?>">';
    username ='@'+'<a href="'+answerurll+'">';
    username += $(this).attr('username')+'</a>';
    //alert(content);
    username +=content;
    // username +=content;
    //alert(username);
    $('#L_content').text(username);

    editIndex = layedit.build('L_content');
  })
     
    //交互
    form.on('submit(*)', function(data){
        data.field.content = layedit.getContent(editIndex);        
        console.log(data);
        $.ajax({
            url: "<?php echo U('home/question/answer_add');?>",//请求地址
            type: "post",//请求方式
            dataType: "json",//返回数据类型
            data: data.field,//发送的参数
            })
            .done(function(response) {
                  if(response.error==0){
                     layer.msg(response.info ,{icon:5});
                  }else{
                     layer.alert(response.info ,{icon:6},function(){
                        location.href = response.url;
                     });
                     
                  }
              })
            .fail(function() {
                alert("ajxs交互失败");
            })  
          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });  


    });
</script>

        <div class="footer">
            <p>
                <a href="<?php echo U('home/index/index');?>">
                    HTZ-交流社区
                </a>
                2016 &copy;
                <a href="javascript:void(0);">
                    欢迎来水
                </a>
            </p>
            <p>
                <a href="javascript:void(0);" target="_blank">
                    扯淡交流-QQ:180683828
                </a>
                <a href="javascript:void(0);" target="_blank">
                    想要HTZ社区模板,小老鼠群主
                </a>
            <!--  <a href="javascript:void(0);" target="_blank">
                    微信公众号
                </a> -->
            </p>
        </div>
    </body>

</html>